<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>项目管理</title>
<%@ include file="/module/js.jsp"%>
</head>
<body>
	<form action="#" name="Form" id="Form" method="post">
	   <%--  <input type="hidden" name="currentPage" value="${currentPage}" /> --%>
		<input type="hidden" name="idList" id="idList"/>
	<%@ include file="/module/orderField.jsp"%>
		<table cellpadding="1" cellspacing="1" border="0">
			<tr>
				<td><input type="button" id="btnQuery" value="查询"
					class="inputButton" /></td>
				<kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId(\"OF_ZLTS_XMG\")%>" key="add">		
				<td><input type="button" id="btnAdd" value="添 加"
					class="inputButton" /></td>
				</kl:permission>
				<kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId(\"OF_ZLTS_XMG\")%>" key="delete">		
				<td><input type="button" id="btnDelete" value="删除"
					 class="inputButton"/></td>
			    </kl:permission>
			</tr>
		</table>
		<table cellpadding="1" cellspacing="1">
			<tr>
				<td>项目名称：</td>
				<td><input type="text" name="projectName" id="projectName"  autocomplete="off" value="${data.projectName}" class="inputText" /></td>
			</tr>
		</table>
		
     <table id="dg"   style="width:100%;"
		data-options="pagination:true,collapsible:true,url:'${basePath}/project/List',method:'post',remoteSort:true,striped:true">
		<thead>
			<tr>
				<th data-options="field:'id',checkbox:true,width:80,align:'left'"></th>
				<th data-options="field:'projectName',sortable:true,nowrap:true,width:350,align:'left',formatter:formater">项目名称</th>
				<th data-options="field:'cycle',nowrap:true,width:200,align:'left',sortable:true">周期</th>
				<th data-options="field:'xm',nowrap:true,width:150,align:'left',sortable:true">负责人</th>
				<th data-options="field:'completeDate',nowrap:true,width:200,align:'left',sortable:true">完成时间</th>
				<th data-options="field:'name',nowrap:true,width:300,align:'left',sortable:true">添加人</th>
				<th data-options="field:'addDate',nowrap:true,width:200,align:'left',sortable:true,formatter:formatDate">添加时间</th>
			    <th data-options="field:'cz',nowrap:true,width:300,align:'left',sortable:true,formatter:formlogo">操作</th> 
			</tr>
		</thead>
	</table>

		
		<script type="text/javascript">
		
		   
		
		    function formater(value, row, index) {
		          return "<a href='${basePath}/project/details?id=" + row.id + "'>" + value + "</a>";
		    } 
	
	
		    function formlogo(value,row, index){
			    /* return "<a href='${basePath}/projectmaterial/projectindex?id=" + row.id+"'>" + '<input type="button" id="btnAddProjectmaterial" value="横向查看材料详情"  class="inputButton"/>' + "</a>"+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='${basePath}/projectmaterial/projectmaterial_List2?id=" + row.id+"'>" + '<input type="button" id="btnAddProjectmaterial" value="纵向查看材料详情"  class="inputButton"/>' + "</a>"; */
		    	   return "<a href='${basePath}/projectmaterial/projectindex?id=" + row.id+"'>" + '<input type="button" id="btnAddProjectmaterial" value="查看材料详情"  class="inputButton"/>' + "</a>";
		    }  
		    
		    
		    function formatDate(value){
		    	var date=new Date(value);
				var y = date.getFullYear();
				var m = date.getMonth()+ 1;
				var d = date.getDate();
				var h= date.getHours();       //获取当前小时数(0-23)
				var mm= date.getMinutes();     //获取当前分钟数(0-59)
				var s= date.getSeconds();     //获取当前秒数(0-59)
				return y +'-'+(m <10?('0'+ m):m)+'-'+(d <10?('0'+ d):d)+'';
			}
		    
			$(document).ready(
							function() {
					         	$('#dg').datagrid({
								 /* onSortColumn :function(sort,order){
								   var _sort=sort;
								   var _order=order;
								   var options=$('#dg').datagrid('getPager').data("pagination").options;
								   var page=options.pageNumber;
								   var pageSize=options.pageSize;
								   window.setTimeout(function(){
									   $.post("${basePath}/project/List",{orderFlag:_order,orderField:_sort,
										   projectName: $('#projectName').val()},
												function(data){
												  $('#dg').datagrid("loadData",data); 
											   });
											   },100);  
								   },
								   rowStyler: function(index,row){
								   }, */
								   
								   onClickRow: function (rowIndex, rowData) {
						                 $(this).datagrid('unselectRow', rowIndex);
						            },
								   
								   onLoadSuccess: function(data){//加载完毕后获取所有的checkbox遍历
									                 if (data.rows.length > 0) {
									                    //循环判断操作为新增的不能选择
									                    var checkbox = $("input[type='checkbox']");

									                    for (var i = 0; i < data.rows.length; i++) {
									                        //根据operate让某些行不可选
									                        if (data.rows[i].logo == 0) {
										                                 $(checkbox.get(i+1)).remove();
										                            	//$("input[type='checkbox']")[i+1].remove();
										                               // $('#dg').datagrid('deleteRow',i);//选择该行 
									                                  // $("input[type='checkbox']")[i + 1].disabled = true;
									                                  //$("input[type='checkbox']")[i].remove();
									                        }
									                    }
									                }
												}
								});
								//查询
								$('#btnQuery')
										.click(
												function() {
													$('#dg').datagrid('load',{
														projectName: $('#projectName').val()
													});
												});
								
								 $('#easyui-ck').click(function() {
									    var data = $("#dg").datagrid("getSelections");
					                    for (var i = 0; i < data.length; i++) {
					                        //根据states让某些行不可选
					                        if (data[i].logo ==0) {
						                            	//$("input[type='checkbox']")[i+1].remove();
						                                 $('#dg').datagrid('unselectRow',i);//选择该行 
						                                 $("#easyui-ck").attr('checked','checked'); 
					                                     // $("input[type='checkbox']")[i + 1].disabled = true;
					                        }
					                    }
									}); 
								 

								$('#btnAdd').click(function() {
									   window.location.href = "${basePath}/project/addInInt";
								});

								$('#btnDelete').click(function() {
									    $("#idList").val("");
													var count = 0;
													var idList = new Array();
												    var sels = $("#dg").datagrid("getSelections");
											    	for(var i in sels){
											    		idList.push(sels[i].id);
											    		count++;
											    	}
													
													if (count == 0) {
														layer.alert("您至少选择一条删除记录信息", {icon: 3});
														return false;
													}else{
														  layer.confirm("您是否删除当前选中数据信息", {icon: 3, title:'提示',skin:'layer-ext-moon'}, function(index){
															    $("#idList").val(idList);
															    document.Form.action = "${basePath}/project/delete";
																document.Form.submit();
														  },function(index){
																layer.close(index);
														  });
													}
												});
						     	});
			
			
			
						$('#btnUpdate').click(function() {
										    var count = 0;
											var id =null;
										    var sels = $("#dg").datagrid("getSelections");
									    	for(var i in sels){
									    		if (count == 1) {
													  layer.alert("只能允许选择一条编辑记录信息", {icon: 3});
													  return false;
												}
									    		id=sels[i].id;
									    		count++;
									    	}
											if (count == 0) {
												 layer.alert("请选择一条编辑记录信息", {icon: 3});
												 return false;
											}else{
												 window.location.href ="${basePath}/project/details?id="+ id;
											}
						});
			 
						
			   if("${msg}"!=""){
			       layer.alert("${msg}", {icon: 6});
			   } 
		</script>
	</form>
</body>
</html>
